package cts.action;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import cts.business.ExamOP;
import cts.business.UserOP;
import cts.db.Exam;
import cts.db.ExamDAO;

public class ExamAction extends ActionSupport {

	/**
	 * @return
	 */
	
	String loginname;
	
	ExamOP examOP = new ExamOP();
	ActionContext ctx = ActionContext.getContext();
	HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
	UserOP userOP = new UserOP();
	
	int eid;
	
	public String execute() {
		// TODO Auto-generated method stub
		return SUCCESS;
	}
	
	public String examList(){
		loginname = (String) ActionContext.getContext().getSession().get("uname");
		List<Exam> elist = examOP.getExams();
		request.setAttribute("examList",elist);
		return SUCCESS;
	}
	
	public String examManage() {
		Set<Exam> eset = userOP.getExams();
		request.setAttribute("examManage",eset);
		return SUCCESS;	
	}
	
	public String attendExam(){
		Exam exam = examOP.getExamDetail(eid);
		request.setAttribute("examDetail", exam);
		return SUCCESS;
	}

	public int getEid() {
		return eid;
	}

	public void setEid(int eid) {
		this.eid = eid;
	}

	public String getLoginname() {
		return loginname;
	}

	public void setLoginname(String loginname) {
		this.loginname = loginname;
	}
	
	
}